package com.controller.api;

import com.biz.BdTeamBiz;
import com.core.Result;
import com.core.ResultGenerator;
import com.entity.model.BdTeam;
import com.entity.model.BdUserinfo;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Condition;

/**
 * Created by asan on 2017-09-05.
 */
@RestController("apiBdTeamController")
@RequestMapping("/api/bdTeam")
public class BdTeamController {
    @Autowired
    private BdTeamBiz bdTeamBiz;

    //代理商通过二维码入驻平台
    @RequestMapping(value = "/joinIn")
    public Result joinIn(BdTeam bdTeam) {
        if (bdTeam != null) {
            Condition cond = new Condition(BdTeam.class);
            cond.createCriteria().andEqualTo("account", bdTeam.getAccount());
            if (bdTeamBiz.countByCond(cond) > 0) {
                return ResultGenerator.genFailResult("该账号已存在");
            } else {
                bdTeam.setStatus(1);
                bdTeamBiz.save(bdTeam);
                return ResultGenerator.genSuccessResult();
            }
        } else {
            return ResultGenerator.genFailResult("参数错误");
        }
    }


    @RequestMapping(value = "/addBdTeam")
    public Result addBdTeam(BdTeam bTeam) {
        if (bTeam != null) {
            Condition cond = new Condition(BdTeam.class);
            cond.createCriteria().andEqualTo("account", bTeam.getAccount());
            Condition cond3 = new Condition(BdTeam.class);
            cond3.createCriteria().andEqualTo("idCard", bTeam.getIdCard());
            if (bdTeamBiz.countByCond(cond) > 0) {
                return ResultGenerator.genFailResult("该手机号已存在,请重新输入");
            }
            if (bdTeamBiz.countByCond(cond3) > 0) {
                return ResultGenerator.genFailResult("该身份证已存在,请重新输入");
            } else {

                bdTeamBiz.save(bTeam);
                return ResultGenerator.genSuccessResult(bTeam);
            }
        } else {
            return ResultGenerator.genFailResult("操作失败");
        }
    }
}
